/**********************************************************************
* File: map.cpp
* ID  : 
* Purpose: Implementation of class Map.
* Date   : 2004/04/28
* Author : T.S.Yo
* Description:
*    The class Map contains a ordered list of locations 
**********************************************************************/

#ifndef MAP_CPP
#define MAP_CPP

#include <string>
#include <iostream>
#include "map.h"


// Constructor
Map::Map()
{
    OrdList<Location> locations(30);
}
        
// Destructor
Map::~Map(){};

//-------------------------------------         
// Get Data of certain location
//-------------------------------------
// Get the exit in certain direction of given location
int Map::getExit(const int &locationID,const char &direction)
{
    Location *tmpLoc;                         // Temp location container
    int result = -1;                         // result to return
    // Search the location
    if(locations.retrieve(locationID, tmpLoc))
    {
        result = tmpLoc->getExit(direction);
//    } else {
//        cout << "Which room are you in? It's not in the map!\n";
    }
    return result;
}

int Map::getPoint(const int &locationID)
{
    Location *tmpLoc;                         // Temp location container
    int result = 0;                          // result to return
    // Search the location
    if(locations.retrieve(locationID, tmpLoc))
    {
        result = tmpLoc->getPoint();
//    } else {
//        cout << "Which room are you in? It's not in the map!\n";
    }
    return result;
}
       
bool Map::getAccessed(const int &locationID)
{
    Location *tmpLoc;                         // Temp location container
    bool result = true;                      // result to return
    // Search the location
    if(locations.retrieve(locationID, tmpLoc))
    {
        result = tmpLoc->getAccessed();
    } else {
        cout << "Which room are you in? It's not in the map!\n";
    }
    return result;
}
       
string Map::getName(const int &locationID)
{
    Location *tmpLoc;                         // Temp location container
    string result = "No name";               // result to return
    // Search the location
    if(locations.retrieve(locationID, tmpLoc))
    {
        result = tmpLoc->getName();
//    } else {
//        cout << "Which room are you in? It's not in the map!\n";
    }
    return result;
}
       
string Map::getSDescr(const int &locationID)
{
    Location *tmpLoc;                         // Temp location container
    string result = "No Short Description";  // result to return
    // Search the location
    if(locations.retrieve(locationID, tmpLoc))
    {
        result = tmpLoc->getSDescr();
//    } else {
//        cout << "Which room are you in? It's not in the map!\n";
    }
    return result;
}
       
string Map::getLDescr(const int &locationID)
{
    Location *tmpLoc;                         // Temp location container
    string result = "No Long Description";   // result to return
    // Search the location
    if(locations.retrieve(locationID, tmpLoc))
    {
        result = tmpLoc->getLDescr();
//    } else {
//        cout << "Which room are you in? It's not in the map!\n";
    }
    return result;
}

void Map::showItemList(const int &locationID)
{
    Location *tmpLoc;                               // Temparory location
    // Search the location
    if(locations.retrieve(locationID, tmpLoc))
    {
        tmpLoc->showItemList();
//    } else {
//        cout << "Which room are you in? It's not in the map!\n";
    }
}
     
// Check if given item is in given location 
bool Map::checkItem(const int &locationID, 
                    const string &itemName, Item &searchItem)
{
    Location *tmpLoc;                         // Temparory location
    bool result = false;                     // Result to return
    // Search the location
    if(locations.retrieve(locationID, tmpLoc))
    {
        result = tmpLoc->searchItem(itemName,searchItem);
//    } else {
//        cout << "Which room are you in? It's not in the map!\n";
    }
    return result;
}

//-------------------------------------         
// Set Data of certain location
//-------------------------------------         
//void Map::setID(const int locationID,const int &newID)

void Map::setExit(const int &locationID, 
                  const int &newExit, const char &direction)
{
    Location *tmpLoc;                         // Temp location container
    // Search the location
    if(locations.retrieve(locationID, tmpLoc))
    {
        tmpLoc->setExit(newExit, direction);
    //    cout << "The location's exits changed.\n";
    } else {
        cout << "Which room are you in? It's not in the map!\n";
    }
}

void Map::setName(const int &locationID,const string &newName)
{
    Location *tmpLoc;                         // Temp location container
    // Search the location
    if(locations.retrieve(locationID, tmpLoc))
    {
        tmpLoc->setName(newName);
        cout << "The location's name changed.\n";
    } else {
        cout << "Which room are you in? It's not in the map!\n";
    }
}

void Map::setAccessed(const int &locationID,const bool &newAccessed)
{
    Location *tmpLoc;                         // Temp location container
    // Search the location
    if(locations.retrieve(locationID, tmpLoc))
    {
        tmpLoc->setAccessed(newAccessed);
    //    cout << "The location's accessed changed to "
    //         << newAccessed << ".\n";
    } else {
        cout << "Which room are you in? It's not in the map!\n";
    }
}

void Map::setPoint(const int &locationID,const int &newPoint)
{
    Location *tmpLoc;                         // Temp location container
    // Search the location
    if(locations.retrieve(locationID, tmpLoc))
    {
        tmpLoc->setPoint(newPoint);
    //    cout << "The location's point changed.\n";
    } else {
        cout << "Which room are you in? It's not in the map!\n";
    }
}

void Map::setSDescr(const int &locationID,const string &newSDescr)
{
    Location *tmpLoc;                         // Temp location container
    // Search the location
    if(locations.retrieve(locationID, tmpLoc))
    {
        tmpLoc->setSDescr(newSDescr);
    //    cout << "The location's short description changed.\n";
    } else {
        cout << "Which room are you in? It's not in the map!\n";
    }
}

void Map::setLDescr(const int &locationID,const string &newLDescr)
{
    Location *tmpLoc;                         // Temp location container
    // Search the location
    if(locations.retrieve(locationID, tmpLoc))
    {
        tmpLoc->setLDescr(newLDescr);
    //    cout << "The location's long description changed.\n";
    } else {
        cout << "Which room are you in? It's not in the map!\n";
    }
}

//-------------------------------------         
// Add/remove item to/from certain location
//-------------------------------------         
void Map::addItem(const int &locationID, const Item &newItem)
{
    Location *tmpLoc;                         // Temp location container
    Item tmpItem = newItem;
    // Search the location
    if(locations.retrieve(locationID, tmpLoc))
    {
        tmpLoc->addItem(newItem);
//        cout << "You put " << tmpItem.getName()
//             << " to "  << tmpLoc->getName() << endl;
//    } else {
//        cout << "Which room are you in? It's not in the map!\n";
    }
}

void Map::dropItem(const int &locationID,const string &itemName)
{
    Location *tmpLoc;                         // Temp location container
    // Search the location
    if(locations.retrieve(locationID, tmpLoc))
    {
        tmpLoc->dropItem(itemName);
//        cout << "You pick " << itemName
//             << " from this location.\n";
//    } else {
//        cout << "Which room are you in? It's not in the map!\n";
    }
}


//-------------------------------------         
// Add/remove a location
//-------------------------------------         
void Map::addLoc(Location &newLocation)
{
    locations.insert(newLocation);
}


#endif    //#ifndef MAP_CPP

